package com.nginx.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nginx.web.domain.HttpInfoQo;
import com.nginx.web.domain.LocationInfoQo;
import com.nginx.web.domain.ServerInfoQo;
import com.nginx.web.domain.UpstreamServerQo;
import com.nginx.web.entity.*;
import com.nginx.web.service.impl.*;
import com.nginx.web.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "server配置")
@RequestMapping("/serverInfo")
@RestController
public class ServerInfoController {

    @Autowired
    private ServerInfoServiceImpl serverInfoService;
    @Autowired
    private LocationInfoServiceImpl locationInfoService;
    @Autowired
    private HttpInfoServiceImpl httpInfoService;
    @Autowired
    private UpstreamServerServiceImpl upstreamServerService;
    @Autowired
    private UpstreamInfoServiceImpl upstreamInfoService;

    @PostMapping("/listServerInfo")
    @ApiOperation(value="查询server配置")
    public Result listServerInfo(ServerInfoQo serverInfoQo){
        Page<ServerInfo> page = serverInfoService.listServerInfo(serverInfoQo);
        return Result.success(page);
    }

    @PostMapping("/updateServerInfo")
    @ApiOperation(value="修改server配置")
    public Result updateServerInfo(ServerInfo serverInfo){
        serverInfoService.updateServerInfo(serverInfo);
        return Result.success();
    }

    @PostMapping("/listLocationInfo")
    @ApiOperation(value="查询location配置")
    public Result listLocationInfo(LocationInfoQo locationInfoQo){
        Page<LocationInfo> page = locationInfoService.listLocationInfo(locationInfoQo);
        return Result.success(page);
    }

    @PostMapping("/updateLocationInfo")
    @ApiOperation(value="修改location配置")
    public Result updateLocationInfo(LocationInfo locationInfo){
        locationInfoService.updateLocationInfo(locationInfo);
        return Result.success();
    }

    @PostMapping("/listHttpInfo")
    @ApiOperation(value="查询http配置")
    public Result listHttpInfo(HttpInfoQo httpInfoQo){
        Page<HttpInfo> page = httpInfoService.listHttpInfo(httpInfoQo);
        return Result.success(page);
    }

    @PostMapping("/updateHttpInfo")
    @ApiOperation(value="修改http配置")
    public Result updateHttpInfo(HttpInfo httpInfo){
        httpInfoService.updateHttpInfo(httpInfo);
        return Result.success();
    }

    @PostMapping("/listUpstreamInfo")
    @ApiOperation(value="查询http配置")
    public Result listUpstreamInfo(HttpInfoQo httpInfoQo){
        Page<UpstreamInfo> page = upstreamInfoService.listUpstreamInfo(httpInfoQo);
        return Result.success(page);
    }

    @PostMapping("/updateUpstreamInfo")
    @ApiOperation(value="修改http配置")
    public Result updateUpstreamInfo(UpstreamInfo upstreamInfo){
        upstreamInfoService.updateUpstreamInfo(upstreamInfo);
        return Result.success();
    }

    @PostMapping("/listUpstreamServerInfo")
    @ApiOperation(value="查询upstreamServer配置")
    public Result listUpstreamServerInfo(UpstreamServerQo qo){
        Page<UpstreamServer> page = upstreamServerService.listUpstreamServerInfo(qo);
        return Result.success(page);
    }

    @PostMapping("/updateUpstreamServerInfo")
    @ApiOperation(value="修改UpstreamServer配置")
    public Result updateUpstreamServerInfo(UpstreamServer upstreamServer){
        upstreamServerService.updateUpstreamServerInfo(upstreamServer);
        return Result.success();
    }

    @PostMapping("/updateUpstreamServerStatus")
    @ApiOperation(value="修改UpstreamServer配置")
    public Result updateUpstreamServerStatus(UpstreamServer upstreamServer){
        upstreamServerService.updateUpstreamServerStatus(upstreamServer);
        return Result.success();
    }

}
